import requests
from user_agent_get import userAgentGet
from bs4 import BeautifulSoup

with open(r'code1/test1.html','r',encoding='utf-8') as f:
    htmlStr=f.read()

soup=BeautifulSoup(htmlStr,'html5lib')

soup1=soup.find_all('a',attrs={'onclick':"_hmt.push(['_trackEvent','web-list-author-text','chick'])"})

for i in soup1:
    print(i.h2.string)

print('-------------------------')
soup2=soup.select(".content span")
print(soup2)
for i in soup2:
    print(i.text)

with open(r"code1/text1.txt",'w',encoding='utf-8') as f:
    for i,j in zip(soup1,soup2):
        inputStr="--------------------\n作者："+i.h2.string.strip()+'\n'
        inputStr=inputStr+j.text.strip()+'\n-------------------\n'
        f.write(inputStr)

    


